package com.study.lxy.netty.netty;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class IOUtil {

    public static String readData(ByteBuf byteBuf) throws Exception{
        byte[] bytes = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(bytes);
        byteBuf.resetReaderIndex();
        return new String(bytes, "UTF-8");
    }

    public static ByteBuf genByteBuf(String data){
        byte[] bytes = data.getBytes();
        return Unpooled.buffer(bytes.length).writeBytes(bytes);
    }

}
